<template>
	<view>
		<view class="calendar">
			<Sign></Sign>
			<text class="title">今日签到换得<text class="red">{{everyday}}</text>积分</text>
			<button class="signBtn" @click="calendarSign">
				<text>{{SignData==0?'立即签到':'今日您已签到'}}</text>
			</button>
		</view>
		<view class="prod"></view>
		<view class="explains">
			<view class="integral">
				<view class="box">
					<image src="http://minipos.posyun3721.com/image/integral.png"></image>
					<text class=""><text class="red">{{integral}}</text>积分</text>
				</view>
				<view class="box" bindtap="navTo">
					<image src="http://minipos.posyun3721.com/image/record.png"></image>
					<text class="">使用记录</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import Sign from '@/components/Sign.vue';
	export default {
		components: {
			Sign,
		},
		data() {
			return {
				integral: '', //积分
				everyday: '', //每日签到的积分
				SignData: 1, //是否签到过 0已签到 1未签到
			};
		},
		onLoad() {
			this.init();
			//积分
			let Member = wx.getStorageSync('Members');
			this.integral = Member[0].Ponit;
		},
		methods: {
			//当前时间
			getNowFormatDate() {
				let date = new Date();
				let seperator1 = "-";
				let seperator2 = ":";
				let month = date.getMonth() + 1;
				let strDate = date.getDate();
				if (month >= 1 && month <= 9) {
					month = "0" + month;
				}
				if (strDate >= 0 && strDate <= 9) {
					strDate = "0" + strDate;
				}
				let currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + date.getHours() +
					seperator2 + date.getMinutes() + seperator2 + date.getSeconds();
				return currentdate;
			},
			//签到
			calendarSign() {
				let data = {
					checkDate: this.getNowFormatDate()
				}
				if (this.SignData == 1) {
					return;
				}
				this.$util.util('membershop/SignIn','','POST').then(res => {
					console.log(res);
					this.$api.msg(res.Msg)
					this.SignData = res.Status
					this.$util.util('MemberShop/GetMemberData','','GET').then(res => {
						console.log(res);
						this.integral = res[0].Ponit;
					}).catch(error => console.log(error))
				}).catch(error => console.log(error));
			},
			//获取已签到日期
			// getCheckedInRecord(year, month, monthDaySize) {
			// 	let calendarSignData = new Array(monthDaySize)
			// 	let data = {
			// 		month: month,
			// 		year: year
			// 	}
			// },
			//初始化
			init() {
				// membershop/getSignInIntegral 获取每日签到赠送的积分
				this.$util.util('membershop/getSignInIntegral','','POST').then(res => {
					console.log(res);
					this.everyday= res.Item1;
					this.SignData= res.Item2;
				}).catch(error => console.log(error));
			},
			navTo() {
				wx.navigateTo({
					url: '/pages/record/record?id=1',
				})
			},
		}
	}
</script>

<style lang="scss">
	/* pages/Member/Sign/Sign.wxss */
	page {
		background: #f8f8f8;
	}

	.calendar {
		margin: 0 4vw;
		padding-bottom: 10rpx;
		border-radius: 15rpx;
		background-color: #fff;
	}

	/* e8e8e8  c5c5c5 ffb3b3*/
	// .content {
	// 	width: 100%;
	// 	height: auto;
	// }

	// .sign {
	// 	width: 100%;
	// 	height: auto;
	// 	background: #fff;
	// }

	.title {
		display: block;
		text-align: center;
		font-size: 32rpx;
		color: #c5c5c5;
		margin-bottom: 30rpx;
	}

	.signBtn {
		width: auto;
		height: 100rpx;
		line-height: 100rpx;
		background: #80c9c7;
		color: #fff;
		margin: 0 48rpx;
		border-radius: 60rpx;
	}

	// .rules {
	// 	width: auto;
	// 	height: auto;
	// 	font-size: 28rpx;
	// 	color: #c5c5c5;
	// 	padding: 0 48rpx;
	// 	background: #fff;
	// 	padding-top: 20rpx;
	// }

	.explains {
		// width: 100%;
		height: auto;
		background: #fff;
		margin: 0 4vw;
	}

	.integral {
		width: auto;
		height: 100rpx;
		display: flex;
		justify-content: space-around;
		align-items: center;
		text-align: center;
		padding: 40rpx 0;
	}

	.box>image {
		width: 48rpx;
		height: 48rpx;
		display: inline-block;
	}

	.box>text {
		font-size: 24rpx;
		color: #000;
		display: block;
	}

	.red {
		color: #ff5556;
	}
</style>
